package customers.restclient;


import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import customers.model.CustomerBasic;
import customers.model.CustomerBasicResp;
import customers.service.CustomerBasicService;

@Controller
@RequestMapping(value="/customerBasicInfoRest",method={RequestMethod.POST})
public class CustomerBasicInfoRest {
	
	private final static Logger logger = LoggerFactory.getLogger(CustomerBasicInfoRest.class);
	
	@Autowired
	private CustomerBasicService customerBasicService;
	
	@RequestMapping("/register")  
    @ResponseBody
    public String insertCustomerBasicInfo(@RequestBody CustomerBasic parm){
		logger.info("会员信息添加 请求{}"+JSONObject.toJSONString(parm));
		CustomerBasic customerBasic = new CustomerBasic();
		customerBasic.setEmail(parm.getEmail());
		customerBasic.setHeadImgUrl(parm.getHeadImgUrl());
		customerBasic.setMobile(parm.getMobile());
		customerBasic.setNickName(parm.getNickName());
		customerBasic.setPassword(parm.getPassword());
		customerBasic.setRegisterSource(parm.getRegisterSource());
		customerBasic.setMemberId(getMemberID());
		CustomerBasicResp<CustomerBasic> res = customerBasicService.insertCustomerBasic(customerBasic);
		if(res.getResultMsg().equals("添加成功")){
			return "OK";
		}else{
			return "no";
		}
		
	}
	
	private String getMemberID(){
		Date currentTime = new Date();  
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");  
        String dateString = formatter.format(currentTime); 
        int x=(int)(Math.random()*900)+100; 
        String m = dateString + x;
        return m;
	}
    

}
